package com.mzj.client;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PushCallback implements MqttCallback {
	
	private static final Logger LOG = LoggerFactory.getLogger(PushCallback.class);

	public void connectionLost(Throwable cause) {
		// 连接丢失后，一般在这里面进行重连
		LOG.info("连接断开，可以做重连");
	}

	public void deliveryComplete(IMqttDeliveryToken token) {
		// publish后会执行到这里
		LOG.info("deliveryComplete---------"+ token.isComplete());
		if(!token.isComplete()) {
			LOG.error("deliveryComplete {}",token.isComplete());
		}
	}

	public void messageArrived(String topic, MqttMessage message) throws Exception {
		// subscribe后得到的消息会执行到这里面
		//System.out.println("接收消息主题:"+topic);
		//System.out.println("接收消息Qos:"+message.getQos());
		LOG.info("接收消息内容:"+new String(message.getPayload()));
	}



}
